<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>图书管理系统 - 登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', sans-serif;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }

        .login-container {
            background: rgba(255, 255, 255, 0.95);
            padding: 2.5rem;
            border-radius: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            width: 90%;
            max-width: 400px;
            transform: translateY(-20px);
            transition: transform 0.3s ease;
        }

        .login-container:hover {
            transform: translateY(-25px);
        }

        h1 {
            color: #2d3748;
            text-align: center;
            margin-bottom: 2rem;
            font-size: 1.8rem;
        }

        .input-group {
            margin-bottom: 1.5rem;
            position: relative;
        }

        input {
            width: 100%;
            padding: 12px 20px;
            border: 2px solid #e2e8f0;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        input:focus {
            border-color: #667eea;
            outline: none;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
        }

        button {
            width: 100%;
            padding: 14px;
            background: #667eea;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        button:hover {
            background: #5a67d8;
        }

        .decoration {
            position: absolute;
            width: 150px;
            height: 150px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            filter: blur(30px);
        }

        .decoration-1 {
            top: -50px;
            left: -50px;
        }

        .decoration-2 {
            bottom: -50px;
            right: -50px;
            background: rgba(102, 126, 234, 0.1);
        }
    </style>
</head>

<body>
    <div class="login-container">
        <div class="decoration decoration-1"></div>
        <div class="decoration decoration-2"></div>
        <h1>欢迎登录图书系统</h1>
        <form>
            <div class="input-group">
                <input type="text" placeholder="用户名" name="userName" id="userName" required>
            </div>
            <div class="input-group">
                <input type="password" placeholder="密码" name="password" id="password" required>
            </div>
            <button onclick="login">立即登录</button>
        </form>
    </div>


    <script src="./jquery-3.7.1.min.js"></script>

    <script>
        // 登录逻辑
        $(function () {
            // 绑定按钮点击事件
            $("button").click(login);

            // 添加回车提交支持
            $(document).keypress(function (e) {
                if (e.which == 13) login();
            });
        });
        function login(event) {
            event.preventDefault(); // 阻止默认行为
            const username = $("#userName").val().trim();
            const password = $("#password").val().trim();

            if (!username || !password) {
                alert("用户名和密码不能为空");
                return;
            }
            $.ajax({
                type: "post",
                url: "/user/login",
                //获取数据
                data: {
                    userName: username,
                    password: password
                },
                //更具后端返回的结果判断是否正确
                success: function (ret) {
                    // console.log(result);
                    if (ret) {
                        //登录成功
                        location.href = "index.html";
                    } else {
                        alert("账号或密码错误！");
                    }
                },
                error: function (xhr) {
                    console.error("请求详情：", xhr);
                    alert("服务器连接异常，请检查网络");
                }
            });
        }
    </script>
</body>

</html>